home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: openLogFile.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:49 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "latch.h"
- #include "link.h"
- #include "lsn.h"
- #include "bf.h"
- #include "volume.h"
- #include "openlog.h"
- #include "trans.h"
- #include "logrecs.h"
- #include "log_intfuncs.h"
- #include "log_extfuncs.h"
- #include "bf_extfuncs.h"
- #include "io_extfuncs.h"
- #include "log_globals.h"
- #include "thread_globals.h"
-
-
- int
- openLogFile (
-
- VOLREC *volRec,
- int writePages,
- int readPages,
- BOOL performRecovery
- )
- {
-
- register OPENLOG *openLog;
- CHECKPOINTMASTER *checkMaster;
- PID pid;
-
-
- TRACE(TR_LOG, TR_LEVEL_1);
-
- /* get a register pointer to the openlog structure */
- openLog = &OpenLog;
-
- /* initialize the open magic */
- INIT_OPENLOG_MAGIC(openLog);
-
- SM_ASSERT(LEVEL_3, MAX_LOGREC_LEN <= RAISETWO(LOGREC_BUF_PAGE2SIZE));
-
- if (bf_OpenServerGroups(writePages, readPages) != esmNOERROR) {
- return(esmFAILURE);
- }
-
- /* mark that the write group is a force group */
- openLog->writeGroup->flags |= (LOG_GROUP|FORCE_GROUP);
-
- /* mark the groups as log groups */
- openLog->readGroup->flags |= LOG_GROUP;
- openLog->writeGroup->flags |= LOG_GROUP;
-
- /*
- * initialize the rest of the openlog structure
- */
- openLog->volid = volRec->header->volid;
- openLog->volRec = volRec;
- openLog->logFileAddr = volRec->header->logFileAddr;
- openLog->readPages = readPages;
- openLog->writePages = writePages;
- openLog->page2size = volRec->header->logFileBlock2size;
- openLog->pageSize = RAISETWO(volRec->header->logFileBlock2size);
- openLog->pageMask = openLog->pageSize - 1;
- openLog->usableBytes = openLog->pageSize - (2 * sizeof(LOGPAGEHDR));
- openLog->filePages = (int) volRec->header->numLogFileBlocks;
- openLog->fileBytes = openLog->filePages * openLog->pageSize;
- openLog->blocksPerPage = RAISETWO(openLog->page2size - MIN_PAGE2SIZE);
- openLog->tailPid = NULLPID;
- openLog->tailLSN = 0;
- openLog->tailBuffer = NULL;
- openLog->tailLink = NULL;
- openLog->activePid = NULLPID;
- openLog->activeLSN = 0;
- openLog->nextValidLSN.wrapCount = 0;
- openLog->nextValidLSN.offset = 0;
- openLog->flags = NOFLAGS;
- openLog->logRecordCount = 2;
- openLog->checkPointCount = 0;
- openLog->lastUsableByte = openLog->pageSize - sizeof(LOGPAGEHDR);
- openLog->checkPointUnique = openLog->logRecordCount;
-
- /* This should already have been set in: processCommandLine() */
- if ( openLog->checkPointInterval < 1) {
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
-
- /*
- * initialize the semaphores and the latches
- */
- initializeSemaphore( &(openLog->writeSemaphore), FALSE );
- initializeSemaphore( &(openLog->readSemaphore), FALSE);
- initializeLatch( &(openLog->logLatch) );
- initializeList( &(openLog->checkPointList) );
- initializeList( &(openLog->recoverList) );
- initializeList( &(openLog->activeList) );
- initializeList( &(openLog->closeList) );
-
- /* construct the pid of the control buffer */
- pid.volid = openLog->volid;
- pid.page = volRec->header->logControlAddr;
-
- /*
- * check to see if we are going to recover the log
- */
- if (performRecovery) {
-
- TRPRINT(TR_LOG, TR_LEVEL_2, ("recovering log"));
-
- /* read in the control buffer */
- if ((openLog->controlBuffer = bf_ReadPage(openLog->readGroup, &pid,
- MIN_PAGE2SIZE, NOFLAGS)) == NULL) {
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /* get a pointer to the checkpoint pointer page */
- checkMaster = (CHECKPOINTMASTER *) openLog->controlBuffer->bufFrame;
-
- /* check the magic number */
- if (checkMaster->magic != CHECKPOINTMASTER_MAGIC) {
-
- fprintf(sm_ErrorStream, "SERVER ERROR: log volume is incorrect.\n");
- fprintf(sm_ErrorStream, "\tHave you recently reformatted it? If so, please regenerate the log.\n");
- fprintf(sm_ErrorStream, "\tRun with -h option for information on regenerating the log.\n");
- SM_ERROR(TYPE_FATAL, esmBADLOGVOLUME);
- }
-
- /*
- * record the location of the initial checkpoint
- */
- openLog->checkPointLSN = checkMaster->checkRecordLSN;
- openLog->checkPointPid = checkMaster->checkRecordLSN.offset >> openLog->page2size;
- openLog->wrapCount = (int) checkMaster->wrapCount;
- TRPRINT(TR_LOG, TR_LEVEL_2, ("checkPointLSN:%d checkPointPid:%d",
- openLog->checkPointLSN.offset, openLog->checkPointPid));
-
- } else {
-
- TRPRINT(TR_LOG, TR_LEVEL_2, ("regenerating log"));
-
- /*
- * read in the control buffer
- */
- if ((openLog->controlBuffer = bf_ReadPage(openLog->readGroup, &pid,
- MIN_PAGE2SIZE, BF_NOREAD)) == NULL) {
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
- }
-
- return(esmNOERROR);
- }
-